package day01;

//输入n计算1~n 全部连接起来的长度(n分别取100,100000,100000000,100000000000000)
public class JoinNumbers4 {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        long n = 100000000;
        //long n=100009;
        //1- 9   9个1位数
        //10-99 90个2位数
        //...
        //10^(k-1)- (10^k-1) 9*(10^(k-1))个k位数

        ///488949
        long s = 0;
        long t = 9, w = 1;
        while (t <= n) {
            s += w * t;
            t = t * 10;
            w++;
        }
        s += (n - Math.pow(10, w - 1) + 1) * w;
        System.out.println(s);
        long end = System.currentTimeMillis();
        System.out.println((end - start) / 1000.0 + " second(s).");
    }
}
